package com.lgc.webtest.controller;

import com.google.gson.reflect.TypeToken;
import com.lgc.webtest.entity.MqMsg;
import com.lgc.webtest.entity.dto.ResponseDto;
import com.lgc.webtest.entity.dto.Test.ProductDetailBo;
import com.lgc.webtest.entity.domain.UserDO;
import com.lgc.webtest.entity.input.DateInput;
import com.lgc.webtest.enums.ErrorCodeEnum;
import com.lgc.webtest.service.HomeService;
import com.lgc.webtest.util.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@RestController
@RequestMapping("/home")
public class HomeController {

    @Autowired
    private HomeService homeService;

    @RequestMapping("/index")
    public String index() {
        return "index1133556789";
    }

    @GetMapping("/index1")
    public String index1() {
        String msg = ErrorCodeEnum.getNameByCode("999");
        return "index1133556789";
    }

    @PostMapping("/index2")
    public String index2() {
        return "index1133556789";
    }

    @RequestMapping("/testLog")
    public String testLog() {

        List<String> list = new ArrayList<>();
        list.stream().filter(p -> p.equals("a")).collect(Collectors.toList());


        List<MqMsg> mqMsgList = new ArrayList<>();
        mqMsgList.stream().sorted(Comparator.comparing(MqMsg::getId));
        mqMsgList.stream().sorted(Comparator.comparing(MqMsg::getId).reversed());

        log.trace("日志输出 trace");
        log.debug("日志输出 debug");
        log.info("日志输出 info");
        log.warn("日志输出 warn");
        log.error("日志输出 error");

        return "testLog";
    }

    @RequestMapping("/getUser")
    public ResponseDto getUser(String userId) { //0000BEBB86399BC6252C933FE8317C48
        ResponseDto responseDto = new ResponseDto();

        UserDO obj = homeService.getUserAccountByUserId(userId);
        responseDto.setContent(obj);

        return responseDto;
    }

    @RequestMapping("/getUserCoin")
    public ResponseDto getUserCoin(String userId, String level, int age) { //2D15CDA222D44AD7A70CC710102EB8DD
        ResponseDto responseDto = new ResponseDto();

        responseDto.setContent(null);//homeService.getUserCoinByUserId(userId));

        return responseDto;
    }

    @RequestMapping("/test")
    public ResponseDto test() {

        String json = "{\"code\":\"0\",\"msg\":\"\",\"content\":{\"currentTime\":\"1558520667969\",\"subjectType\":\"1\",\"virtualArea\":\"欧洲\",\"virtualAreaNo\":\"VA0017\",\"storeType\":1,\"isSupportTicketCode\":\"0\",\"baseType\":\"A01\",\"videoUrl\":\"\",\"videoPicUrl\":\"\",\"isShelve\":\"0\",\"category\":\"A01B05C39D02 \",\"erpCategory\":\"A01B01C01D02\",\"isShowCart\":\"1\",\"postArea\":\"0\",\"paymentArea\":\"2\",\"tariff\":\"含关税运费\",\"flagList\":[\"欧洲\"],\"flagColorList\":\"#0700c5\",\"isUsed\":\"0\",\"used\":{},\"notice\":{\"salesPromotion\":{},\"fastDispatch\":\"\",\"acceptance\":\"\",\"tag\":[{\"name\":\"颜色\",\"value\":[\"白色\",\"黑色\"]},{\"name\":\"尺码\",\"value\":[\"S\",\"L\"]}],\"color\":\"#888888\"},\"basic\":{\"isSoldOut\":\"0\",\"productId\":\"30670887\",\"productName\":\"直发商品小于4900\",\"prefix\":\"\",\"suffix\":\"\",\"advertWord\":\"直发商品小于4900 12221\",\"brand\":{\"isShown\":\"1\",\"alias\":\"品牌店\",\"nameEN\":\"PRADA\",\"nameCN\":\"普拉达\",\"id\":\"B0002\",\"pic\":\"https://qapic.shangpin.com/e/s/15/06/24/20150624134718063994-0-0.jpg\",\"about\":\"PRADA以完美主义著称。兼具经典色彩和创新精神的时尚理念,成为享誉世界的传奇品牌。\",\"allNum\":\"-1\",\"newestNum\":\"-1\",\"collections\":\"-1\",\"aboutUrl\":\"http://qa.m.shangpin.com/brandStory/index?type=0\\u0026id=B0002\"},\"activityId\":\"\",\"collect\":{\"isCollected\":\"0\",\"id\":\"0\"},\"isAfterSale\":\"1\",\"isSize\":\"1\",\"isBrandStyle\":\"1\",\"commentCount\":\"2\",\"sales\":\"-1\",\"collections\":\"-1\",\"isPackage\":\"0\",\"info\":[\"商品编号:30670887\",\"商品名称:直发商品小于4900\",\"\\u003cp\\u003e\\r\\n\\t温馨提示：\\r\\n\\u003c/p\\u003e\\r\\n\\u003cp\\u003e\\r\\n\\t本品为内衣类贴身商品，不支持退换，请谨慎购买，为保障您权益，建议您签收时当面验货。\\r\\n\\u003c/p\\u003e\",\"特殊说明:1\"],\"attributeInfo\":[{\"name\":\"商品编号\",\"value\":\"30670887\"},{\"name\":\"商品名称\",\"value\":\"直发商品小于4900\"},{\"name\":\"温馨提示\",\"value\":\"\\u003cp\\u003e\\r\\n\\t\\r\\n\\u003c/p\\u003e\\r\\n\\u003cp\\u003e\\r\\n\\t本品为内衣类贴身商品，不支持退换，请谨慎购买，为保障您权益，建议您签收时当面验货。\\r\\n\\u003c/p\\u003e\"},{\"name\":\"特殊说明\",\"value\":\"1\"}],\"kindTipUrl\":\"http://qa.m.shangpin.com/product/kindly_reminder?pNo=30670887\",\"detailBannerFlagList\":[{\"key\":null,\"title\":\"正品保证\",\"banner\":\"https://qapic.shangpin.com/e/s/18/12/25/20181225193103604377-0-0.jpg\"},{\"key\":null,\"title\":\"会员日免邮\",\"banner\":\"https://qapic.shangpin.com/e/s/18/12/25/20181225193103604377-0-0.jpg\"},{\"key\":null,\"title\":\"积分抵现\",\"banner\":\"https://qapic.shangpin.com/e/s/18/12/25/20181225193103604377-0-0.jpg\"}],\"recommend\":\"12\",\"proDetailMemo\":\"安定的柔道\",\"consumerNotification\":\"\",\"defaultIndex\":{\"propsIndex\":\"0\",\"firstPropIndex\":\"0\",\"secondPropIndex\":\"0\"},\"miniSkuNo\":\"\",\"firstPropName\":\"颜色\",\"secondPropName\":\"国际码\",\"screenSizeName\":\"国际码\",\"allPics\":[\"https://qapic.shangpin.com/f/p/18/12/25/20181225112533182445-10-10.jpg\",\"https://qapic.shangpin.com/f/p/18/12/26/20181226155610715146-10-10.jpg\"],\"props\":[{\"title\":\"海外极速达\",\"importType\":\"1\",\"promotionWarmup\":\"\",\"servePoint\":\"\",\"serveInfo\":\"不支持7天无理由退换;预采商品\",\"serveInfoMore\":\"该商品为海外发货，商品售价已含税费，由于奢侈品的特殊性，建议您在实体店或官网了解体验后再下单\",\"server\":[{\"serveIcon\":\"https://qapic.shangpin.com/e/s/19/01/21/20190121174106071667-0-0.jpg\",\"serveInfo\":\"不支持7天无理由退换\",\"serveInfoMore\":\"该商品为海外发货，商品售价已含税费，由于奢侈品的特殊性，建议您在实体店或官网了解体验后再下单\"},{\"serveIcon\":\"https://qapic.shangpin.com/e/s/19/01/21/20190121174107070245-0-0.jpg\",\"serveInfo\":\"预采商品\",\"serveInfoMore\":\"此商品为海外预采商品，有可能会发生未配到货情况，请您随时关注订单状态\"}],\"deliveryPoint\":\"发货后预计7-10个工作日送达\",\"deliveryInfo\":\"发货后预计7-10个工作日送达\",\"deliveryInfoMore\":\"\",\"isPriorBuy\":\"0\",\"priorBuyInfo\":\"\",\"DepositexpansionInfo\":{\"presaleFlag\":\"0\",\"tagName\":\"\",\"tagTitle\":\"\",\"refTitle\":\"\",\"refUrl\":\"\",\"buyTitle\":\"\",\"buyColor\":\"\",\"icon\":\"\",\"width\":\"60\",\"height\":\"60\",\"prefix\":\"\",\"presaleProcess\":[]},\"seckill\":{\"isSeckill\":\"1\",\"startTime\":\"1558519200000\",\"price\":\"¥0\"},\"firstProps\":[{\"icon\":\"https://qapic.shangpin.com/f/p/18/12/25/20181225112533182445-10-10.jpg\",\"firstProp\":\"白色\",\"isSecondProp\":\"1\",\"pics\":[],\"secondProps\":[{\"sku\":\"30670887001\",\"secondProp\":\"L\",\"screenSizeValue\":\"L\",\"sizeAbout\":[{\"name\":\"国际码\",\"value\":\"L\"}],\"taxPromotionPrice\":\"4060\",\"taxStandardPrice\":\"5000\",\"isExchange\":\"1\",\"count\":1,\"priceTag\":[{\"type\":\"1\",\"priceTitle\":\"\",\"priceValue\":\"¥4060\",\"color\":\"#c62026\",\"isShow\":\"1\",\"isCut\":\"0\",\"fontStyle\":\"3\"},{\"type\":\"2\",\"priceTitle\":\"\",\"priceValue\":\"¥5000\",\"color\":\"#9B9B9B\",\"isShow\":\"1\",\"isCut\":\"1\",\"fontStyle\":\"1\"}],\"platinumPrice\":4421.00,\"goldPrice\":4421.00,\"promotionPrice\":\"0\",\"isPromotion\":\"1\",\"saleDesc\":\"\",\"isSupportDiscount\":\"1\",\"vipPromAmount\":\"203\",\"goldCoin\":\"203\",\"fashionBeansAmount\":\"406\",\"discountPrice\":\"3857\",\"buyPrice\":\"3857\"}]}]}]},\"share\":{\"title\":\"【直发商品小于4900】\",\"desc\":\"尚品网这件宝贝很不错，快来瞧一瞧！\",\"url\":\"http://qa.m.shangpin.com/product/detail?productNo=30670887\",\"pic\":\"https://qapic.shangpin.com/f/p/18/12/25/20181225112533182445-10-10.jpg\"},\"overseasInfo\":{},\"guaranteeImg\":\"http://pic2.shangpin.com/group1/M00/17/D5/rBQKaFXedyKAdi81AAB-OJ7GLjQ111.jpg\",\"isShowVipBuy\":1,\"vipBuy\":{\"btnIsShow\":\"1\",\"tagName\":\"金牌价\",\"buyDesc\":\"开通金牌会员立省\",\"refTitle\":\"9.9开卡\\u003e\\u003e\",\"buyUrl\":\"https://m.shangpin.com/t/vip/buy\",\"icon\":\"https://pic5.shangpin.com/e/s/19/03/30/20190330165254355480-0-0.jpg\"},\"extensionBuy\":{\"btnIsShow\":\"0\",\"tagName\":\"\",\"buyDesc\":\"\",\"refTitle\":\"\",\"buyUrl\":\"http://m.shangpin.com/meet/index?id=03245\\u0026type=1\"},\"DiscountList\":[{\"type\":\"1\",\"key\":\"返豆\",\"value1\":\"店庆！购买可返\",\"value2\":\"×5倍时尚豆\",\"keyColor\":\"#000000\",\"valueColor\":\"#000000\"}],\"DetailPicList\":[],\"BuyInstructionsPicList\":[]}}";
        ResponseDto<ProductDetailBo> productDetailObj = JsonUtil.fromJson(json, new TypeToken<ResponseDto<ProductDetailBo>>() {
        });


        return productDetailObj;
    }

    @RequestMapping("/testDate")
    public ResponseDto testDate(@RequestBody DateInput dateInput) {
        ResponseDto responseDto = new ResponseDto<>();
        responseDto.setContent(dateInput);

        DateInput newInput = new DateInput();
        newInput.setInputDate(Calendar.getInstance().getTime());
        newInput.setIsTest(11);

        String json = JsonUtil.toJson(newInput);

        long timeStamp = newInput.getInputDate().getTime();

        return responseDto;
    }
}
